package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kaili.basic.mapper.StrategySiteMapper;
import com.kaili.basic.pojo.dto.MdmStrategyMainSetAddDto;
import com.kaili.basic.pojo.dto.MdmStrategySiteAddDto;
import com.kaili.basic.pojo.entity.MdmStrategyMainEntity;
import com.kaili.basic.pojo.entity.MdmStrategySiteEntity;
import com.kaili.basic.service.IStrategySiteService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* 设备策略 service实现类
* @author:zhangjl
* @Time: 2019-07-24
* @Copyright: ©  杭州凯立通信有限公司 版权所有
* @Warning: 本内容仅限于公司内部传阅,禁止外泄或用于其它商业目的
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class StrategySiteServiceImpl extends ServiceImpl<StrategySiteMapper, MdmStrategySiteEntity>  implements IStrategySiteService {

    @Override
    public boolean add(Integer id,MdmStrategyMainSetAddDto dto) {
        MdmStrategySiteAddDto siteAddDto = dto.getStrategySiteDetail();
        MdmStrategySiteEntity siteEntity = new MdmStrategySiteEntity();
        BeanUtils.copyProperties(siteAddDto,siteEntity);
        siteEntity.setStrategyId(id);
        this.insert(siteEntity);

        return true;
    }

    @Override
    public boolean modify(MdmStrategyMainEntity entity) {
        //1、删除设备策略
//        this.del(entity.getId());
        //2、修改设备类
        MdmStrategySiteEntity siteEntity = entity.getStrategySiteDetail();
        siteEntity.setStrategyId(entity.getId());
        Wrapper<MdmStrategySiteEntity> wrapper = new EntityWrapper<>();
        wrapper.where("strategy_id ={0}", siteEntity.getStrategyId());
       this.update(siteEntity,wrapper);

        return true;
    }

    @Override
    public boolean del(Integer id) {
        Wrapper<MdmStrategySiteEntity> wrapper = new EntityWrapper<>();
        wrapper.where("strategy_id ={0}", id);
        this.delete(wrapper);
        return true;
    }

}
